.class public Lorg/microemu/app/util/MRUList;
.super Ljava/lang/Object;
.source "MRUList.java"

# interfaces
.implements Lorg/microemu/app/util/XMLItem;


# static fields
.field private static final MAXCAPACITY_DEFAULT:I = 0xa

.field private static final serialVersionUID:J = 0x1L


# instance fields
.field private classXMLItem:Ljava/lang/Class;

.field private items:Ljava/util/Stack;

.field private itemsName:Ljava/lang/String;

.field private listener:Lorg/microemu/app/util/MRUListListener;

.field protected maxCapacity:I

.field private modified:Z


# direct methods
.method public constructor <init>(Ljava/lang/Class;Ljava/lang/String;)V
    .locals 1
    .parameter "classXMLItem"
    .parameter "itemsName"

    .prologue
    .line 60
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 48
    const/16 v0, 0xa

    iput v0, p0, Lorg/microemu/app/util/MRUList;->maxCapacity:I

    .line 50
    new-instance v0, Ljava/util/Stack;

    invoke-direct {v0}, Ljava/util/Stack;-><init>()V

    iput-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    .line 58
    const/4 v0, 0x1

    iput-boolean v0, p0, Lorg/microemu/app/util/MRUList;->modified:Z

    .line 61
    iput-object p1, p0, Lorg/microemu/app/util/MRUList;->classXMLItem:Ljava/lang/Class;

    .line 62
    iput-object p2, p0, Lorg/microemu/app/util/MRUList;->itemsName:Ljava/lang/String;

    .line 63
    return-void
.end method

.method private fireListener(Ljava/lang/Object;)V
    .locals 1
    .parameter "item"

    .prologue
    .line 84
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->listener:Lorg/microemu/app/util/MRUListListener;

    if-eqz v0, :cond_0

    .line 85
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->listener:Lorg/microemu/app/util/MRUListListener;

    invoke-interface {v0, p1}, Lorg/microemu/app/util/MRUListListener;->listItemChanged(Ljava/lang/Object;)V

    .line 88
    :cond_0
    return-void
.end method


# virtual methods
.method public getMaxCapacity()I
    .locals 1

    .prologue
    .line 98
    iget v0, p0, Lorg/microemu/app/util/MRUList;->maxCapacity:I

    return v0
.end method

.method public push(Ljava/lang/Object;)Ljava/lang/Object;
    .locals 2
    .parameter "item"

    .prologue
    .line 66
    instance-of v0, p1, Lorg/microemu/app/util/XMLItem;

    if-nez v0, :cond_0

    .line 67
    new-instance v0, Ljava/lang/ClassCastException;

    invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/ClassCastException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 69
    :cond_0
    const/4 v0, 0x1

    iput-boolean v0, p0, Lorg/microemu/app/util/MRUList;->modified:Z

    .line 70
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v0}, Ljava/util/Stack;->size()I

    move-result v0

    iget v1, p0, Lorg/microemu/app/util/MRUList;->maxCapacity:I

    if-le v0, v1, :cond_1

    .line 71
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v0}, Ljava/util/Stack;->pop()Ljava/lang/Object;

    .line 73
    :cond_1
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v0, p1}, Ljava/util/Stack;->remove(Ljava/lang/Object;)Z

    .line 74
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v0}, Ljava/util/Stack;->empty()Z

    move-result v0

    if-eqz v0, :cond_2

    .line 75
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v0, p1}, Ljava/util/Stack;->add(Ljava/lang/Object;)Z

    .line 79
    :goto_0
    invoke-direct {p0, p1}, Lorg/microemu/app/util/MRUList;->fireListener(Ljava/lang/Object;)V

    .line 80
    return-object p1

    .line 77
    :cond_2
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    const/4 v1, 0x0

    invoke-virtual {v0, p1, v1}, Ljava/util/Stack;->insertElementAt(Ljava/lang/Object;I)V

    goto :goto_0
.end method

.method public read(Lnanoxml/XMLElement;)V
    .locals 7
    .parameter "xml"

    .prologue
    .line 119
    const/4 v5, 0x0

    iput-boolean v5, p0, Lorg/microemu/app/util/MRUList;->modified:Z

    .line 120
    iget-object v5, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v5}, Ljava/util/Stack;->removeAllElements()V

    .line 121
    const-string v5, "maxCapacity"

    const/16 v6, 0xa

    invoke-virtual {p1, v5, v6}, Lnanoxml/XMLElement;->getIntAttribute(Ljava/lang/String;I)I

    move-result v5

    iput v5, p0, Lorg/microemu/app/util/MRUList;->maxCapacity:I

    .line 122
    invoke-virtual {p1}, Lnanoxml/XMLElement;->enumerateChildren()Ljava/util/Enumeration;

    move-result-object v2

    .local v2, en:Ljava/util/Enumeration;
    :cond_0
    :goto_0
    invoke-interface {v2}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v5

    if-eqz v5, :cond_1

    .line 123
    invoke-interface {v2}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Lnanoxml/XMLElement;

    .line 124
    .local v4, xmlChild:Lnanoxml/XMLElement;
    invoke-virtual {v4}, Lnanoxml/XMLElement;->getName()Ljava/lang/String;

    move-result-object v5

    iget-object v6, p0, Lorg/microemu/app/util/MRUList;->itemsName:Ljava/lang/String;

    invoke-virtual {v5, v6}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v5

    if-eqz v5, :cond_0

    .line 126
    :try_start_0
    iget-object v5, p0, Lorg/microemu/app/util/MRUList;->classXMLItem:Ljava/lang/Class;

    invoke-virtual {v5}, Ljava/lang/Class;->newInstance()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lorg/microemu/app/util/XMLItem;

    .line 127
    .local v1, element:Lorg/microemu/app/util/XMLItem;
    invoke-interface {v1, v4}, Lorg/microemu/app/util/XMLItem;->read(Lnanoxml/XMLElement;)V

    .line 128
    iget-object v5, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v5, v1}, Ljava/util/Stack;->add(Ljava/lang/Object;)Z
    :try_end_0
    .catch Ljava/lang/InstantiationException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/lang/IllegalAccessException; {:try_start_0 .. :try_end_0} :catch_1

    goto :goto_0

    .line 129
    .end local v1           #element:Lorg/microemu/app/util/XMLItem;
    :catch_0
    move-exception v5

    move-object v0, v5

    .line 130
    .local v0, e:Ljava/lang/InstantiationException;
    new-instance v5, Ljava/lang/RuntimeException;

    invoke-direct {v5, v0}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/Throwable;)V

    throw v5

    .line 131
    .end local v0           #e:Ljava/lang/InstantiationException;
    :catch_1
    move-exception v5

    move-object v0, v5

    .line 132
    .local v0, e:Ljava/lang/IllegalAccessException;
    new-instance v5, Ljava/lang/RuntimeException;

    invoke-direct {v5, v0}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/Throwable;)V

    throw v5

    .line 137
    .end local v4           #xmlChild:Lnanoxml/XMLElement;
    .end local v0           #e:Ljava/lang/IllegalAccessException;
    :cond_1
    iget-object v5, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v5}, Ljava/util/Stack;->empty()Z

    move-result v5

    if-nez v5, :cond_2

    .line 139
    iget-object v5, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    iget-object v6, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v6}, Ljava/util/Stack;->size()I

    move-result v6

    invoke-virtual {v5, v6}, Ljava/util/Stack;->listIterator(I)Ljava/util/ListIterator;

    move-result-object v3

    .local v3, iter:Ljava/util/ListIterator;
    :goto_1
    invoke-interface {v3}, Ljava/util/ListIterator;->hasPrevious()Z

    move-result v5

    if-eqz v5, :cond_2

    .line 140
    invoke-interface {v3}, Ljava/util/ListIterator;->previous()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lorg/microemu/app/util/XMLItem;

    .line 141
    .restart local v1       #element:Lorg/microemu/app/util/XMLItem;
    invoke-direct {p0, v1}, Lorg/microemu/app/util/MRUList;->fireListener(Ljava/lang/Object;)V

    goto :goto_1

    .line 144
    .end local v3           #iter:Ljava/util/ListIterator;
    .end local v1           #element:Lorg/microemu/app/util/XMLItem;
    :cond_2
    return-void
.end method

.method public save(Lnanoxml/XMLElement;)V
    .locals 4
    .parameter "xml"

    .prologue
    .line 106
    iget-boolean v2, p0, Lorg/microemu/app/util/MRUList;->modified:Z

    if-nez v2, :cond_0

    .line 116
    :goto_0
    return-void

    .line 109
    :cond_0
    invoke-virtual {p1}, Lnanoxml/XMLElement;->removeChildren()V

    .line 110
    const-string v2, "maxCapacity"

    iget v3, p0, Lorg/microemu/app/util/MRUList;->maxCapacity:I

    invoke-static {v3}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v3

    invoke-virtual {p1, v2, v3}, Lnanoxml/XMLElement;->setAttribute(Ljava/lang/String;Ljava/lang/Object;)V

    .line 111
    iget-object v2, p0, Lorg/microemu/app/util/MRUList;->items:Ljava/util/Stack;

    invoke-virtual {v2}, Ljava/util/Stack;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, iter:Ljava/util/Iterator;
    :goto_1
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_1

    .line 112
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lorg/microemu/app/util/XMLItem;

    .line 113
    .local v0, element:Lorg/microemu/app/util/XMLItem;
    iget-object v2, p0, Lorg/microemu/app/util/MRUList;->itemsName:Ljava/lang/String;

    invoke-virtual {p1, v2}, Lnanoxml/XMLElement;->addChild(Ljava/lang/String;)Lnanoxml/XMLElement;

    move-result-object v2

    invoke-interface {v0, v2}, Lorg/microemu/app/util/XMLItem;->save(Lnanoxml/XMLElement;)V

    goto :goto_1

    .line 115
    .end local v0           #element:Lorg/microemu/app/util/XMLItem;
    :cond_1
    const/4 v2, 0x0

    iput-boolean v2, p0, Lorg/microemu/app/util/MRUList;->modified:Z

    goto :goto_0
.end method

.method public setListener(Lorg/microemu/app/util/MRUListListener;)V
    .locals 1
    .parameter "l"

    .prologue
    .line 91
    iget-object v0, p0, Lorg/microemu/app/util/MRUList;->listener:Lorg/microemu/app/util/MRUListListener;

    if-eqz v0, :cond_0

    .line 92
    new-instance v0, Ljava/lang/IllegalArgumentException;

    invoke-direct {v0}, Ljava/lang/IllegalArgumentException;-><init>()V

    throw v0

    .line 94
    :cond_0
    iput-object p1, p0, Lorg/microemu/app/util/MRUList;->listener:Lorg/microemu/app/util/MRUListListener;

    .line 95
    return-void
.end method

.method public setMaxCapacity(I)V
    .locals 0
    .parameter "maxCapacity"

    .prologue
    .line 102
    iput p1, p0, Lorg/microemu/app/util/MRUList;->maxCapacity:I

    .line 103
    return-void
.end method
